"""
Sample requests:

curl -v "http://127.0.0.1:8000/user?name=hazadus&password=123" | jq
curl -v "http://127.0.0.1:8000/check_user?name=hazadus&password=123"
"""

from fastapi import Depends, FastAPI, params

app = FastAPI()


# Depencdency function:
def user_dep(name: str = params, password: str = params):
    return {"name": name, "valid": True}


@app.get("/user")
async def get_user(user: dict = Depends(user_dep)) -> dict:
    """
    `user_dep` gets called on each endpoint call.
    """
    return user


def check_dep(name: str = params, password: str = params):
    if not name:
        raise


@app.get("/check_user", dependencies=[Depends(check_dep)])
def check_user() -> bool:
    return True


if __name__ == "__main__":
    import uvicorn

    uvicorn.run("app:app", reload=True)
